package com.itheima.service.imp;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;
import com.itheima.dao.ReportDao;
import com.itheima.dao.SetMealDao;
import com.itheima.service.ReportService;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = ReportService.class)
public class ReportServiceImpl implements ReportService {
    @Autowired
    private OrderDao orderDao;

    @Autowired
    private MemberDao memberDao;

    @Autowired
    private ReportDao reportDao;



    @Override
    public Map<String, Object> getBusinessReportData() throws Exception {
/*
*                   reportDate:'2020-1-12',
                    todayNewMember :10,
                    totalMember :20,
                    thisWeekNewMember :0,
                    thisMonthNewMember :0,
                    todayOrderNumber :0,
                    todayVisitsNumber :0,
                    thisWeekOrderNumber :0,
                    thisWeekVisitsNumber :0,
                    thisMonthOrderNumber :0,
                    thisMonthVisitsNumber :0,
                    hotSetmeal :[
                        {name:'阳光爸妈升级肿瘤12项筛查（男女单人）体检套餐',setmeal_count:200,proportion:0.222},
                        {name:'阳光爸妈升级肿瘤12项筛查体检套餐',setmeal_count:200,proportion:0.222}
                    ]*/
            Map<String,Object> map = new HashMap<>();
//                获取今日日期
        String today = DateUtils.parseDate2String(DateUtils.getToday());
//        本周第一天
        String this_week = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
//        本月的1号
        String thisMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
        map.put("reportDate",today);

//        获取今日新增会员数
       Integer newMember = memberDao.findNewMemberByDay(today);
        map.put("todayNewMember",newMember);
//       查询总会员数
       Integer allMember = memberDao.findAll();
        map.put("totalMember",allMember);
//       本周新增会员数
        Integer thisWeekNewMember = memberDao.findCountByWeek(this_week);
        map.put("thisWeekNewMember",thisWeekNewMember);
//        本月新增会员数
        String this_month = thisMonth.substring(0, 7);
        Integer thisCountMonth= memberDao.findCountByMonth(this_month);
        map.put("thisMonthNewMember",thisCountMonth);
//        今日预约人数
        Integer orderConuntToday = orderDao.findTodayOrder(today);
        map.put("todayOrderNumber",orderConuntToday);
//        今日到诊人数
        Integer ordreCountArriveToday = orderDao.findByArriveToday(today,"已到诊");
        map.put("todayVisitsNumber",ordreCountArriveToday);
//         本周预约人数
        Integer orderCountWeek = orderDao.findByOrderCountThisWeek(this_week);
        map.put("thisWeekOrderNumber",orderCountWeek);
//        本周到诊人数
        Integer arriveThisWeek = orderDao.findByArriveThisWeek(this_week,"已到诊");
        map.put("thisWeekVisitsNumber",arriveThisWeek);
//        本月预约人数
        Integer orderCountThisMonth = orderDao.findByOrderCountThisMonth(this_month);
        map.put("thisMonthOrderNumber",orderCountThisMonth);

//        本月到诊人数
        Integer orderArriveThisMonth = orderDao.findByOrderArriveThisMonth(this_month,"已到诊");
        map.put("thisMonthVisitsNumber",orderArriveThisMonth);
//        查找热门预约套餐
//        1.总预约数
        List<Map<String,Object>> hotSetmeal = reportDao.findHotSetmeal();
        map.put("hotSetmeal",hotSetmeal);
        Integer countAllOrder  = orderDao.findCountAllOrder();

        map.put("proportion",countAllOrder);
        return map;
    }
}
